package com.taro.jpushplugin;

import android.os.Bundle;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.widget.Toast;

import com.unity3d.player.UnityPlayerActivity;


/**
 * Copyright © 2014  JPUSH. All rights reserved.
 *
 * @Title: UnityPluginActivity.java
 * @Prject: unity-jpush-plugin
 * @Package: com.example.jpushdemo
 * @Description: TODO
 * @author: zhangfl
 * @date: 2014-4-16 下午7:07:02
 * @version: V1.0
 */
public class UnityPluginActivity extends UnityPlayerActivity {
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    private long presstime = 0;

    public boolean onKeyDown(int var1, KeyEvent var2) {
        if (var1 == KeyEvent.KEYCODE_BACK) {
            if (presstime == 0) {
                presstime = SystemClock.uptimeMillis();
                Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            } else {
                long current = SystemClock.uptimeMillis();
                if (current - presstime > 2000) {
                    presstime = SystemClock.uptimeMillis();
                    Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                }else {
                    super.onBackPressed();
                }
            }
        }
        return super.onKeyDown(var1, var2);
    }


}
